package net.zigin.nhi.could.waste.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import io.swagger.models.auth.In;
import net.zigin.commons.util.ReflectUtil;
import net.zigin.nhi.could.waste.dto.WarnBaseDto;
import net.zigin.nhi.could.waste.model.WarnBase;
import net.zigin.nhi.could.waste.service.WarnBaseService;

import net.zigin.nhi.could.waste.vo.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * WarnBase控制器类
 *
 * @author mgw1986
 * @version V1.0
 * @ClassName: WarnBaseController
 * @date 2021-9-20 19:47:08
 */
@Api(tags = "预警管理")
@RestController
@RequestMapping("/warnBase")
public class WarnBaseController extends BaseController {
    @Autowired
    private WarnBaseService warnBaseService;

    @ApiOperation("预警处理")
    @ApiImplicitParam(name = "warnBaseDto", value = "预警信息", required = true, dataType = "WarnBaseDto")
    @PostMapping("/dealWith")
    public JsonForResult dealWith(@RequestBody WarnBaseDto warnBaseDto) {
        warnBaseService.dealWith(warnBaseDto);
        return JsonForResult.builder().success(true).build();
    }

    @ApiOperation("预警列表")
    @ApiImplicitParam(name = "warnBaseDto", value = "预警信息", required = true, dataType = "WarnBaseDto")
    @PostMapping("/getList")
    public JsonForResult<List<WarnBaseVo>> getList(@RequestBody WarnBaseDto warnBaseDto) {
        List<WarnBaseVo> list = warnBaseService.getList(warnBaseDto);
        Integer count = warnBaseService.getCount(warnBaseDto);
        return JsonForResult.<List<WarnBaseVo>>builder().data(list).total(count).success(true).build();
    }

    @ApiOperation("预警详情")
    @ApiImplicitParam(name = "id", value = "预警id", required = true, dataType = "String")
    @GetMapping("/getById/{id}")
    public JsonForResult<WarnBaseVo> getById(@PathVariable String id) {
        WarnBaseVo warnBaseVo = warnBaseService.getInfoById(id);
        return JsonForResult.<WarnBaseVo>builder().data(warnBaseVo).success(true).build();
    }

    @ApiOperation("首页-总量统计")
    @GetMapping("/situation")
    public JsonForResult<WarnCountVo> situation() {
        WarnCountVo result = warnBaseService.situation();
        return JsonForResult.<WarnCountVo>builder().data(result).success(true).build();
    }

    @ApiOperation("获取时间重量")
    @ApiImplicitParam(name = "wasteBaseId", value = "医废ID", required = true, dataType = "String")
    @GetMapping("/getWarnTimeAndWeight/{wasteBaseId}")
    public JsonForResult<WasteWarnVo> getWarnTimeAndWeight(@PathVariable("wasteBaseId") String wasteBaseId){
        WasteWarnVo wasteWarnVo = warnBaseService.getWarnTimeAndWeight(wasteBaseId);
        return JsonForResult.<WasteWarnVo>builder().data(wasteWarnVo).success(true).build();
    }

}
